import requests
import json

url_prefix_api = 'http://cloud/prod-api'
path_login = '/api/v1/auth/login'
username = 'admin'
password = '123123'
params = {'username': username, 'password': password}
# 登录获取Token
resp = requests.post(url_prefix_api + path_login, "{}", params=params)

if resp.status_code == 200:
    resp_data = json.loads(resp.content)
    accessToken = resp_data['data']['accessToken']
    tokenType = resp_data['data']['tokenType']
    print(f"accessToken:{accessToken}, tokenType:{tokenType}")

    path_dataset_filter = '/api/task/data/filter'
    req = {"task_id": 1, "data_type": "时序表"}  # data_type取值包含: 时序表、数据表、文档、音视频、图片、文件
    headers = {'Content-type': 'application/json', 'Authorization': f"{tokenType} {accessToken}"}
    resp = requests.post(url_prefix_api + path_dataset_filter, json.dumps(req), headers=headers)
    if resp.status_code == 200:
        resp_data = json.loads(resp.content)
        task_list = resp_data['data']
        print(json.dumps(task_list, ensure_ascii=False, indent='  '))

else:
    print(resp.content)
